'use strict';
const { src, dest,task, watch, series, parallel } = require('gulp');
const sass = require('gulp-sass')(require('sass'));
var autoprefixer = require('gulp-autoprefixer');

var argv = require('yargs')
    .option('sassPath', {
        alias: 's',
        describe: "where's your sass?",
        default: './resources/static/sass'
    })
    .option('npmPath', {
        alias: 'n',
        describe: "where's your npm?",
        default: './node_modules'
    })
    .option('cssPath', {
        alias: 'c',
        describe: "where do you want your css?",
        default: './resources/static/css'
    })
    .help('help')
    .argv;

var sassOptions = {
    errLogToConsole: true,
    outputStyle: 'expanded',
    includePaths: [
        argv.sassPath,
        argv.npmPath + '/bootstrap-sass/assets/stylesheets'
    ]
};

var autoprefixerOptions = {
    browsers: ['last 2 versions', '> 5%', 'Firefox ESR']
};
// gulp.task('default', ['sass']);
task('default', parallel( buildSass));
task('watch', series('default', parallel(watchAll)));

function buildSass(done) {
    src(argv.sassPath + '/**/*.scss')
        .pipe(sass(sassOptions).on('error', sass.logError))
        .pipe(autoprefixer(autoprefixerOptions))
        .pipe(dest(argv.cssPath));
    done()
};

function watchAll(done) {
    watch(argv.sassPath + '/**/*.scss',series(buildSass));
    done();
};
